# -*- coding:utf-8 -*-

from rest_framework.viewsets import ModelViewSet
from ..models.theme import Theme
from ..ser.themeSer import ThemeSer
from Apps.common.response import SuccessResponse


class ThemeView(ModelViewSet):
    queryset = Theme.objects.all()
    authentication_classes = []
    serializer_class = ThemeSer

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return SuccessResponse(serializer.data)

    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return SuccessResponse(serializer.data, status=200, headers=headers)
